import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  // 静态路由范围
  {
    path: '/login',
    component: () => import('@/views/Login/index'),
    hidden: true
  },
  {
    name: 'Agreement',
    path: '/agreement',
    hidden: true,
    component: () => import('@/views/agreement')
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/Dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

/* 
动态路由范围
*/
  // 生产管理
  {
    path:'/production',
    component: Layout,
    hidden:false,
    redirect: '/production/sheep',
    meta: { title: '生产管理', icon: 'produce' },
    children:[{
      name:'Sheep',
      path:'sheep',
      component: () => import('@/views/production/sheep'),
      meta: { title: '物流管理' }
    },{
      name: 'Feeding',
      path: 'feeding',
      component: () => import('@/views/production/feeding'),
      meta: { title: '查询管理' }
    }]
  },
  //css3特效
  {
    path: '/cssThree',
    name: 'cssThree',
    component: Layout,
    meta: { title: 'css3特效', icon: 'star' },
    children: [{
      path: 'slidebartitle',
      component: () => import('@/views/cssThree/SlideBarTitle'),
      meta: { title: '幻灯条标题' }
    },
    {
      path: 'buttonHoverStroke',
      component: () => import('@/views/cssThree/buttonHoverStroke'),
      meta: { title: '按钮悬停描边' }
    },
    {
      path: 'buttonHoverMultistroke',
      component: () => import('@/views/cssThree/buttonHoverMultistroke'),
      meta: { title: '按钮悬停多重描边' }
    },
    {
      path: 'buttonHoverFlashes',
      component: () => import('@/views/cssThree/buttonHoverFlashes'),
      meta: { title: '按钮悬停闪烁' }
    },
    {
      path: 'dotAnimation',
      component: () => import('@/views/cssThree/dotAnimation'),
      meta: { title: '圆点动画' }
    },
    {
      path: 'snowAnimation',
      component: () => import('@/views/cssThree/snowAnimation'),
      meta: { title: '飘雪动画' }
    },
    {
      path: 'maskEffect',
      component: () => import('@/views/cssThree/maskEffect'),
      meta: { title: '遮罩效果' }
    }]
  },
  {
    path: '/tool',
    name: 'Tool',
    component: Layout,
    meta: { title: '工具', icon: 'setting' },
    children: [
      {
        path: 'quillEditor',
        component: () => import('@/views/tool/quillEditor'),
        meta: { title: '富文本编辑器' }
      },
      {
        path: 'iconSelect',
        component: () => import('@/views/tool/iconSelect'),
        meta: { title: 'icon下拉' }
      }
    ]
  },
  // 数据分析
  {
    path: '/dataAnalysis',
    name: 'dataAnalysis',
    component: Layout,
    redirect: '/dataAnalysis/production',
    meta: { title: '数据分析', icon: 'chart' },
    children: [{
      path: 'production',
      component: () => import('@/views/dataAnalysis/production'),
      meta: { title: '生产数据看板' }
    },
    {
      path: 'health',
      component: () => import('@/views/dataAnalysis/health'),
      meta: { title: '健康数据看板' }
    }]
  },
  //员工客户管理
  {
    path: '/crm',
    component: Layout,
    hidden: false,
    meta: { title: '员工客户管理', icon: 'people' },
    redirect: '/crm/index',
    children:[{
      path: 'index',
      component: () => import('@/views/crm'),
      meta: { title: '员工管理' }
    },
    {
      path: 'customer',
      hidden: false,
      component: () => import('@/views/crm/customer'),
      meta: { title: '客户管理' }
    },
    {
      path: 'supplier',
      hidden: false,
      component: () => import('@/views/crm/supplier'),
      meta: { title: '供应商管理' }
    }]
  },
  // 后台管理
  {
    path: '/system',
    name: 'system',
    component: Layout,
    redirect: '/system/account',
    meta: { title: '后台管理', icon: 'system' },
    children: [{
      path: 'account',
      component: () => import('@/views/system/account'),
      meta: { title: '账号管理' }
    },
    {
      path: 'role',
      component: () => import('@/views/system/role'),
      meta: { title: '角色管理' }
    },
    {
      path: 'menu',
      component: () => import('@/views/system/menu'),
      meta: { title: '菜单管理' }
    }]
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// reset 路由方法
export function resetRouter() {
  // 得到一个全新的router实例对象
  const newRouter = createRouter()
  // 使用新的路由记录覆盖掉老的路由记录
  router.matcher = newRouter.matcher // reset router
}

export default router
